<?php 
Box::$description["BoxGoogleMaps"] = "Google map";
Core::LoadExtraConfig("google_maps");
/**
*Google Maps plugin.
*@author Willy Gardiol <willy@gardiol.org>
*@version 1.0
*@package Boxes
*@subpackage GoogleMaps
*/
class BoxGoogleMaps extends Box
{
	public function __construct( $title )
	{
		parent::__construct( $title, "popup" );
		$this->SetStorage(array("width" => false,
							"height" => false,
							"text" => "we need a text here",
							"address" => "V. Valperga Caluso 11, 10128, Torino, Italy" ) );
	}

	protected function GenerateHtml()
	{
		$key = Core::GetConfig("key", "google_maps");
		$width = $this->Get("width");
		$height = $this->Get("height");

		Core::AddJsScript("http://maps.google.com/maps?file=api&amp;v=2&amp;key=$key");
		Core::AddJsScript("Engine/plugins/boxes/google_maps/google_maps.js");

		$style = new Css( array( "width" => $width,
							"height" => $height ) );

		$this->AddControl( "GoogleMapsQuery", I18N("Configure") );

		$html = new HtmlDiv(array("class" => "google_maps",
										"style" => $style));
		$id = $html->GetId();

		$addr = CoreUtils::Php2Js( $this->Get("address") );
		$text = CoreUtils::Php2Js($this->Get("text") );

		Core::AddJsCode( "\$('#$id').mapMe({addr:$addr,info:$text})" );
		return $html;
	}
}
/**
*Configure Google Maps plugin.
*@author Willy Gardiol <willy@gardiol.org>
*@version 1.0
*@package Boxes
*@subpackage GoogleMaps
*/
class GoogleMapsQuery extends BoxEdit
{
	protected function BoxEdit( $box )
	{
		$html = new HtmlFieldset(I18N("Configure Google Map"));

		$html->Append( $form = new HtmlEditRequest());

		$form->Append( $fs = new HtmlFieldset(I18N("Width")));
		$fs->Append( new HtmlTextInput("", "gm_width", $box->Get("width") ));

		$form->Append( $fs = new HtmlFieldset(I18N("Height")));
		$fs->Append( new HtmlTextInput("", "gm_height", $box->Get("Height") ));

		$form->Append( $fs = new HtmlFieldset(I18N("Address")));
		$fs->Append( new HtmlTextareaInput("gm_address", $box->Get("address")));

		$form->Append( $fs = new HtmlFieldset(I18N("Info text")));
		$fs->Append( new HtmlTextareaInput("gm_text", $box->Get("text")));

		$form->AppendSubmit( I18N("Save configuration") );

		return $html;
	}

	protected function BoxSave( $box )
	{
		$width = Core::PostVar("gm_width", $box->GetWidth(), "string" );
		$box->Set("width", $width ) && $this->SetReload(true);

		$height = Core::PostVar("gm_height", $box->GetHeight(), "string" );
		$box->Set("height", $height ) && $this->SetReload(true);

		$addr = Core::PostVar("gm_address", $box->GetAddress(), "string" );
		$box->Set("address", $addr ) && $this->SetReload(true);

		$text = Core::PostVar("gm_text", $box->GetText(), "string" );
		$box->Set("text", $text ) && $this->SetReload(true);
		return I18N("Google Map configured!");
	}
}

?>